package com.school.admin.common.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @program: business
 * @description: 编码工具类
 * @author: zzz
 * @create: 2020-08-01 13:58
 **/
public class CodeUtils {

    /**
     * @param s 数据库中存储编码的最大值
     * @return java.lang.String
     * @desc : TODO 生成编码
     * @author: zzz
     * @date 2020-08-01 13:59:10
     */
    public static String getMaxIncrease(String s, String parentId) {

        if (StringUtils.isEmpty(s)){
            return parentId+"01";
        }
        char c = s.charAt(s.length() - 1);
        char[] chars = s.toCharArray();
        char[] format = String.valueOf(String.format("%d", Integer.valueOf(c + "") + 1)).toCharArray();
        chars[chars.length - 1] = format[format.length - 1];
        return new String(chars);
    }

    //
    /**
     * 实例:TEACHER(老师)||STUDENT(学生)+学院统一编号+专业编号+当前年月日时分秒+随机6位数
     * @desc : TODO 生成学号||教师工号
     * @author: zzz
     * @param numbering
     * @param coding
     * @param type
     * @return java.lang.String
     * @date 2020-08-01 15:07:45
     */
    public static String produceNumber(String numbering,String coding,String type){
        String format = DateUtil.format(new Date(), "yyyyMMddHHmmss");
        String a = RandomUtil.randomString("1234567890", 6);
        return type+numbering+coding+format+a;
    }



}
